goog.provide('dkpoints.ServiceProvider');



/**
 * Service Provider
 * This singleton contains references to all of the subsystems of the app:
 * - Status panel
 * - RPC service
 * - Auth system
 * - The bodyContent element on the page.
 * - Navigation manager (set after construction)
 * - The app's base URL (set after construction)
 * - New dependencies will be added as needed.
 *
 * The main purpose of this object is to be passed to navigation handlers when
 * they are constructed.  The handlers will use getters to retrieve references
 * to the dependencies they need and will let the reference to the
 * ServiceProvider object go out of scope so as not to retain references to
 * subsystems they don't need.
 *
 * Setters are only provided for dependencies that need to be calculated or
 * created after construction of the ServiceProvider object, such as the
 * navigation manager (which relies on the SP as a dependency for other
 * subsystems) and the baseUR (which is calculated in the nav manager
 * constructor).
 *
 * @param {dkpoints.auth.Auth} auth The auth subsystem instance.
 * @param {dkpoints.rpc.RPCService} rpc The RPC service instance.
 * @param {dkpoints.status.Status} status The status panel manager instance.
 * @param {!Element} bodyContent Reference to the bodyContent element (UI root).
 *
 * @constructor
 */
dkpoints.ServiceProvider = function(auth, rpc, status, bodyContent) {
  /**
   * @type {dkpoints.auth.Auth}
   * @private
   */
  this.auth_ = auth;

  /**
   * @type {dkpoints.rpc.RPCService}
   * @private
   */
  this.rpc_ = rpc;

  /**
   * @type {dkpoints.status.Status}
   * @private
   */
  this.status_ = status;

  /**
   * @type {!Element}
   * @private
   */
  this.bodyContent_ = bodyContent;
};


/**
 * This is done in the dkpoints.nav.Nav constructor.
 * @param {string} baseURL Everything before the '#' in the URL.
 */
dkpoints.ServiceProvider.prototype.setBaseURL = function(baseURL) {
  /**
   * @type {string}
   * @private
   */
  this.baseURL_ = baseURL;
};


/**
 * @return {string} The base URL for the app.
 */
dkpoints.ServiceProvider.prototype.getBaseURL = function() {
  return this.baseURL_;
};


/**
 * This is done in the dkpoints.nav.Nav constructor.
 * @param {dkpoints.nav.Nav} nav The navigation manager.
 */
dkpoints.ServiceProvider.prototype.setNavManager = function(nav) {
  /**
   * @type {dkpoints.nav.Nav}
   * @private
   */
  this.nav_ = nav;
};


/**
 * @return {dkpoints.nav.Nav} Returns the navigation manager.
 */
dkpoints.ServiceProvider.prototype.getNavManager = function() {
  return this.nav_;
};


/**
 * @return {dkpoints.auth.Auth} Getter for the app's Auth/Auth manager.
 */
dkpoints.ServiceProvider.prototype.getAuth = function() {
  return this.auth_;
};


/**
 * @return {dkpoints.rpc.RPCService} Getter for the app's RPC service.
 */
dkpoints.ServiceProvider.prototype.getRPC = function() {
  return this.rpc_;
};


/**
 * @return {dkpoints.status.Status} Getter for the app's Status panel manager.
 */
dkpoints.ServiceProvider.prototype.getStatusManager = function() {
  return this.status_;
};


/**
 * @return {!Element} Getter for the bodyContent element.
 */
dkpoints.ServiceProvider.prototype.getBodyContent = function() {
  return this.bodyContent_;
};
